<?php
// +----------------------------------------------------------------------
// |日志管理
// +----------------------------------------------------------------------
// |Data:2015-03-20 16:25
// +----------------------------------------------------------------------
// |Author: 吕志雄 <870923001@qq.com>
// +----------------------------------------------------------------------
namespace Admin\Controller;
use Common\Controller\AdminCommonController;

class LogController extends AdminCommonController{
    private $_model;
    public function _initialize(){
        parent::_initialize();
        $this->_model = D('Admin/ManageLog');
    }

    /**
     * 列表
     */
    public function index(){
        $where = $this->search();
        $p = I('get.p',0);
        $list = $this->_model->getList($where,$p);

        $this->assign($list);
        $this->display();
    }

    /**
     * 搜索
     * @return array
     */
    private function search(){
        $keywords = urldecode(I('get.keywords','','trim'));
        $start_time = I('get.start_time');
        $end_time = I('get.end_time');

        $where = array();
        !empty($keywords) && $where['nickname|agent|detail'] = array('like',$keywords);
        if(!empty($start_time)){
            $where['ctime'] = array('egt',strtotime($start_time));
        }

        if(!empty($end_time)){
            $where['ctime'] = array('elt',strtotime($end_time)+86400);
        }

        if(!empty($start_time) && !empty($end_time)){
            $where['ctime'] = array('between',array(strtotime($start_time),strtotime($end_time)+86400));
        }

        $this->assign('keywords',$keywords);
        $this->assign('start_time',$start_time);
        $this->assign('end_time',$end_time);

        return $where;
    }

    /**
     * 删除
     */
    public function del(){
        if(IS_POST){
            $ids = I('post.id');
            empty($ids) && $this->returnData('请选择操作项！');

            $ids = is_array($ids) ? arr2str($ids) : $ids;

            $where = array();
            $where['id'] = array('in',$ids);
            if($this->_model->del($where)){
                $this->returnData('删除成功！',1);
            }else{
                $this->returnData('删除失败！');
            }
        }else{
            $this->returnData('请求方式错误！');
        }
    }
}
?>